


function varargout = console(varargin)
% CONSOLE MATLAB code for console.fig
%      CONSOLE, by itself, creates a new CONSOLE or raises the existing
%      singleton*.
%
%      H = CONSOLE returns the handle to a new CONSOLE or the handle to
%      the existing singleton*.
%
%      CONSOLE('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in CONSOLE.M with the given input arguments.
%
%      CONSOLE('Property','Value',...) creates a new CONSOLE or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before console_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to console_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help console

% Last Modified by GUIDE v2.5 27-Jan-2014 19:20:58



% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @console_OpeningFcn, ...
                   'gui_OutputFcn',  @console_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before console is made visible.
function console_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to console (see VARARGIN)

% Choose default command line output for console
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes console wait for user response (see UIRESUME)
% uiwait(handles.figure1);

setEnv();

% --- Outputs from this function are returned to the command line.
function varargout = console_OutputFcn(hObject, eventdata, handles) 
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;


% --- Executes on button press in pushbutton_processFrames.
function pushbutton_processFrames_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton_processFrames (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
controller();

% --- Executes on button press in pushbutton_loadStudy.
function pushbutton_loadStudy_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton_loadStudy (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
    
    workingDir = 'C:\Users\rniehaus\Documents\Elegans\';
    filter = sprintf('%s*.proj', workingDir);
    [fileName,pathName,filterIndex] = uigetfile(filter);
     studyInstanceName = fileName(1:length(fileName) - 5);
    [dataList, suppData] = getStudyInstance(workingDir, studyInstanceName);
    
      
    fh = gcf;
    setappdata(fh,'dataList',dataList); 
    setappdata(fh,'suppData',suppData); 

 %printToConsole(hObject, 'Study load completed.');
fprintf('Study Load Completed') ;

%get the handle to teh current figure

% --- Executes on button press in pushbutton_segsAndSkels.
function pushbutton_segsAndSkels_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton_segsAndSkels (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% fh = gcf;
% x = getappdata(fh,'dataList'); 
% y = getappdata(fh,'suppData'); 
% analyzeSegAndSkels(x.dataList, y.suppData);

fh = gcf;
dataList = getappdata(fh,'dataList'); 
suppData = getappdata(fh,'suppData'); 
analyzeWormConsole(dataList, suppData);






% --- Executes on button press in pushbutton_LAIISignature.
function pushbutton_LAIISignature_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton_LAIISignature (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
fh = gcf;
x = getappdata(fh,'dataList'); 
y = getappdata(fh,'suppData'); 
analyzeLaiiSig(y, x);

% --- Executes on button press in pushbutton_analyzeWidthProfiles.
function pushbutton_analyzeWidthProfiles_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton_analyzeWidthProfiles (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
fh = gcf;
y = getappdata(fh,'suppData'); 
plotWidthProfile(y);


    
    
   
   
    
    function printToConsole(hObject, msg)
        GuiHandle = ancestor(hObject, 'figure');
        handles = guidata(GuiHandle);
        oldmsgs = cellstr(get(handles.text_console,'String'));
        set(handles.text_console,'String',[oldmsgs;{msg}] );
        drawnow;
        fprintf(msg);




% --- Executes on button press in pushbutton_delauneySkeleton.
function pushbutton_delauneySkeleton_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton_delauneySkeleton (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
